package video.dataAndType

fun main(args: Array<String>) {

    val list = listOf(11, 22, 33, 44)

    for ((index,value) in list.withIndex()){
        println("$index----$value")
    }

    for (indexValue in list.withIndex()){
        println("${indexValue.index}=======${indexValue.value}")
    }

    val myIntList = MyIntList()
    myIntList.add(22)
    myIntList.add(55)
    myIntList.add(66)

    //in 相当于iterator 操作符
    for (value in myIntList){
        println("$value...........")
    }

}


class MyIntList{

    private val list = ArrayList<Int>()

    fun add(value:Int){
        list.add(value)
    }

    fun remove(value: Int){
        list.remove(value)
    }

    operator fun iterator():MyIterator{
        return MyIterator(list.iterator())
    }

}

class MyIterator(val iterator: Iterator<Int>){

    operator fun next():Int{
        return iterator.next()
    }

    operator fun hasNext():Boolean{
        return iterator.hasNext()
    }
}

